<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>

	<link rel="stylesheet" href="Public/Bootstrap/Css/bootstrap.min.css" />
	<link rel="stylesheet" href="Public/admin/Css/common.css" />
	<link rel="stylesheet" href="Public/uploadify/uploadify.css" />
	<script type="text/javascript" src='Public/admin/Js/jquery-1.7.2.min.js'></script>
	<script type="text/javascript" src='Public/Uploadify/jquery.uploadify.js'></script>
	<script type="text/javascript" src='Public/Ueditor/ueditor.config.js'></script>
	<script type="text/javascript" src='Public/Ueditor/ueditor.all.min.js'></script>
		<!--载入百度编辑器-->
	    	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.config.js"></script>
    		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.all.min.js"> </script>
    		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	
	<style type="text/css">
		/*去掉uploadify上传按钮的边框*/
	    .uploadify-button {
	        background-color: transparent;
	        border: none;
	        padding: 0;
	    }
	    .uploadify:hover .uploadify-button {
	        background-color: transparent;
    	}
    	.hide{
    		display: none;
    	}
    	body{
    		margin-bottom: 100px;
    	}
	</style> 
	<script>
		$(function(){
	
			$('select[name=cid]').change(function(){
				//选中分类后,给option添加tid，让隐藏域获取tid
				$tid=$(':selected').attr('tid');
				$('input[name=tid]').val($tid);
				$('.dAttr').remove();
				$('.dSpec').remove();
				$.ajax({
					type:"post",
					url:"<?php echo U('ajaxGetAttr')?>",
					data:{tid:$tid},
					dataType:'json',
					success:function(data){
						var attr="";
						var spec="";
						$.each(data,function(k,v){
							if(v.class==0){
								//为属性
								attr +='<tr><td>'+v.taname+'：</td><td><select name="attr['+v.taid+'][gtvalue]"><option value="0">请选择</option>'
								$.each(v.tavalue, function(kk,vv) {
									attr += '<option value="'+vv+'">'+vv+'</option>'
					
								});
								attr += '</select></td></tr>';
							}else{
								//否则为规格
								spec += '<tr><td>'+v.taname+'</td><td><select name="spec['+v.taid+'][gtvalue][]"><option value="0">请选择</option>';
												$.each(v.tavalue, function(kk,vv){
													spec += '<option value="'+vv+'">'+vv+'</option>';
												})
												spec += '</select></td><td>附加价格</td><td>';
												spec += '<input type="text" name="spec['+v.taid+'][added][]" id="" value="0" />';
												spec += '</td><td><a href="javascript:;" class="hd-btn hd-btn-success hd-btn-sm addSpec">增加</a></td></tr>';
							}
							
						});
						$('#attr').html(attr);
						$('#spec').html(spec);
					}
				});
			})
			//点击增加，增加一条规格
			$('.addSpec').live('click',function(){
				var tr=$(this).parents('tr').clone();
				var del='<a href="javascript:;" class="hd-btn hd-btn-danger hd-btn-sm delSpec">删除</a>';
				tr.find('.addSpec').remove();
				tr.find('td').eq(4).append(del);
				$(this).parents('tr').after(tr);
			})
			//点击删除规格
			$('.delSpec').live('click',function(){
				$(this).parents('tr').remove();
			})
		})
		
	</script>
		
<!--上传图片和删除图片-->
<script>
	 $(function() {
            $('#pic').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeDesc' : '上传文件',//上传描述
                'fileTypeExts' : '*.jpg;*.png;*.bmp',
                'swf'      : 'Public/uploadify/uploadify.swf',
                'uploader' : "<?php echo U('ajaxUpload')?>",
                'buttonText':'选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 1000,//上传文件数
                'width':65,
                'height':25,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
                    data=$.parseJSON(data);
                    var imageUrl = data.image?data.url:'<?php echo __PUBLIC__?>/image/default.png';
					var li = '<li url="'+data.path+'"><img src="'+data.path+'" style="width:50px"/>';
					 li += '<input type="hidden" name="pic[]" id="" value="'+data.path+'" />';
					 li += '<a href="javascript:;" class="delImg" style="color:red">X</a></li>';
                    $("#pic-list").prepend(li);
                }
            });
            $(".delImg").live("click",function(){
						var url = $(this).parents("li").attr("url");
						var _this=$(this);
						$.ajax({
							type:"post",
							url:"<?php echo U('ajaxDelImg')?>",
							data:{url:url},
							dataType:"json",
							success:function(data){
								if(data==1){
									_this.parents("li").remove();
								}
							}
						});
					})
      
        //图册图片上传
          $('#photo').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeDesc' : '上传文件',//上传描述
                'fileTypeExts' : '*.jpg;*.png;*.bmp',
                'swf'      : 'Public/uploadify/uploadify.swf',
                'uploader' : "<?php echo U('ajaxUpload')?>",
                'buttonText':'选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 1000,//上传文件数
                'width':65,
                'height':25,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
                    data=$.parseJSON(data);
                    var imageUrl = data.image?data.url:'<?php echo __PUBLIC__?>/image/default.png';
					var li = '<li url="'+data.path+'"><img src="'+data.path+'" style="width:50px"/>';
					 li += '<input type="hidden" name="big[]" id="" value="'+data.path+'" />';
					 li += '<a href="javascript:;" class="delImg1" style="color:red">X</a></li>';
                    $("#photo-list").prepend(li);
                }
            });
            $(".delImg1").live("click",function(){
						var url = $(this).parents("li").attr("url");
						var _this=$(this);
						$.ajax({
							type:"post",
							url:"<?php echo U('ajaxDelImg')?>",
							data:{url:url},
							dataType:"json",
							success:function(data){
								if(data==1){
									_this.parents("li").remove();
								}
							}
						});
					})
        });
</script>
</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">

	<form action="" method='post'>
		<fieldset>
			<legend>添加商品</legend>
			<table class='table table-bordered table-hover'>
				<thead>
					<tr>
						<th colspan="2" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
							<select name="cid" >
								<option value="0">-请选择-</option>
									<?php foreach ($cateData as $v){?>
									<option value="<?php echo $v['cid']?>" tid='<?php echo $v['tid']?>'<?php if($goodsData['cid']==$v['cid']){?>
                 selected="selected" 
               <?php }?>><?php echo $v['_name']?></option>
									<?php }?>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="bid">
								<option value="0">-请选择-</option>
									<?php foreach ($brandData as $va){?>
								
									<option value="<?php echo $va['bid']?>" <?php if($va['bid']==$goodsData['bid']){?>
                 selected="selected" 
               <?php }?>><?php echo $va['bname']?></option>
									<?php }?>
									
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname' value="<?php echo $goodsData['gname']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='unit' value="<?php echo $goodsData['unit']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='marketprice' value="<?php echo $goodsData['marketprice']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='shopprice' value="<?php echo $goodsData['shopprice']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='click' value="<?php echo $goodsData['click']?>"/>
						</td>
					</tr>
				</tbody>
			</table>

			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="info">
				<div class="dAttr">
				<?php foreach ($typeData as $vt){?>
				<tr>
					<td><?php echo $vt['taname']?></td>
					<td>
						<select name="attr[<?php echo $vt['taid']?>][gtvalue]">
							<option value="0">请选择</option>
							<?php foreach ($vt['tavalue'] as $va){?>
							<option value="<?php echo $va?>" <?php if(in_array($va,$gtvalue['gtvalue'])){?>
                 selected="selected" 
               <?php }?>><?php echo $va?></option>

							<?php }?>
						</select>
							<input type="hidden" name="taid" id="taid" value="<?php echo $vt['taid']?>" />
						
					</td>
					
				</tr>
				<?php }?>
				</div>
			</table>
			<script>
				$(function(){
					$('.addThing').click(function(){
						var $tr=$(this).parents('tr').clone();
						$(this).parents('tr').after($tr);
						var $del='<td><a href="javascript:;" class="btn btn-danger btn-sm oldDel">删除</a></td>';
						$tr.find('td').eq(4).remove();
						$tr.append($del);
					})
				})
			//点击删除规格
				$('.oldDel').live('click',function(){
					$(this).parents('tr').remove();
				})
			</script>
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
				<div class="dSpec">
				<?php foreach ($aa as $vt){?>
				<tr>
					<td>
						<?php echo $vt['taname']?>
						</td>
					<td>
						<select name="spec[<?php echo $vt['taid']?>][gtvalue][]">
							<option value="0">请选择</option>
							<?php foreach ($vt['tavalue'] as $va){?>
							<option value="<?php echo $va?>" <?php if($vt['gtvalue']==$va){?>
                 selected="selected" 
               <?php }?>><?php echo $va?></option>
							<?php }?>
						</select>
					</td>
					<td>附加价格</td>
					<td>
						<input type="text" name="spec[<?php echo $vt['taid']?>][added][]" value="<?php echo $vt['added']?>"/>
					</td>
					<td>
						<a href="javascript:; " class="btn btn-info btn-sm addThing">增加</a>
					</td>
				</tr>
				<?php }?>
				</div>
			</table>
			
			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">列表图</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<input type="file" name='pic[]' id='pic' value=""/>
					</td>
					<td id='pic-list'>
						<?php foreach ($goodsData['pic'] as $vp){?>
						<img src="<?php echo $vp?>" alt="" style="width: 50px;"/>
						<a href="javascript:;" id="oldDel">X
						<input type="hidden" name="pic[]" id="d" value="<?php echo $vp?>" />
						</a>
						<?php }?>
					</td>
				</tr>
			</table>
			<script>
				$(function(){
					$('#oldDel').live('click',function(){
						$(this).prev('img').remove();
						$(this).remove();
						$vu=$(this).find('#d').val();
						$vus=$('#pics').val();
						$.ajax({
							type:"post",
							url:"<?php echo U('Goods/ajaxOld')?>",
							data:{vu:$vu,vus:$vus},
							dataType:'json',
							success:function(data){
							$('#pic-list').append('<input type="hidden" name="pic" id="pic" value="'+data+'"/>');
							}
						});
					})
				})
			</script>
			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">商品图册</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<input type="file" name='big[]' id='photo' />
					</td>
					<td id='photo-list'>
						<?php foreach ($detailData['big'] as $vu){?>
						<img src="<?php echo $vu?>" alt="" style="width: 50px;"/>
						<a href="javascript:;" id="oldDel1">X
						<input type="hidden" name="big[]" id="d" value="<?php echo $vu?>" />
							
						</a>
						<?php }?>
					</td>
				</tr>
			</table>
			<script type="text/javascript">
				$(function(){
					$('#oldDel1').live('click',function(){
						$(this).prev('img').remove();
						$(this).remove();
					})
				})
			</script>
			
			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">商品详细</th>
				</tr>
				<tr class="info">
					<td>
						
						<script id="editor" type="text/plain" style="width:100%;" name="intro"><?php echo $detailData['intro']?></script>
					    <script>
					        var ue = UE.getEditor('editor');
					        
					    </script>
					</td>
				</tr>
			</table>
			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">售后服务</th>
				</tr>
				<tr class="info">
					<td>
						<script id="editor1" type="text/plain" style="width:100%;" name="server"><?php echo $detailData['server']?></script>
					    <script>
					        var ue = UE.getEditor('editor1');
					    </script>
					</td>
				</tr>
			</table>
			<input type="hidden" name="aid" id="aid" value="<?php echo $adminData[0]['aid']?>" />
			
			<input type="hidden" name='tid' value="<?php echo $goodsData['tid']?>"/>
			
			
			<input type="hidden" name="gid" id="gid" value="<?php echo $gide?>" />
			<input type="submit" value="确认修改" class="btn btn-primary btn-block btn-large"/>
		</fieldset>
	</form>

	</div>
	</div>
	</div>
</body>
</html>